<template>
  <div>
    <Nav></Nav>
    <!--头部-->
    <div class="head">
      <div class="header-cont">
        <img class="logo" src="../../../static/login/logo.png" />
        <span>{{title}}</span>
      </div>
    </div>

    <div class="con">
      <div class="reg-wrap">
        <!--注册页面-->
        <div class="reg">

          <div class="iphoneCode">
            <input class="inp" @blur="yzIphone()" v-model="iphone"  type="text" placeholder="请输入手机号">
            <img v-if="iphoneTrue" src="../../../static/login/check .png" height="12" width="12"/>
          </div>

          <p class="false">
            <span v-if="bol"><img src="../../../static/login/alert.png" alt="">手机号码不正确,请重新输入</span>
          </p>

          <input class="inp"  v-model="password" type="password" placeholder="请输入密码（6-20位号码字符）">
          <input class="inp repwd" v-model="repassword" type="password" placeholder="请再次输入密码确认">

          <div class="clearfix yzm">
            <input class="inp-yzm" v-model="code" type="text" placeholder="验证码">
            <Code class="code" ref="zi"></Code>
          </div>

          <div class="iphoneyzm">
            <input class="inp " :disabled="dis1" v-model="iphoneyzm"  type="text" placeholder="手机验证码">
            <button @click="getCode()" :class="yzm?'yzmbtn':'aa'" :disabled='dis2'>
              {{tit}}
            </button>
          </div>

          <div class="zi-dl" >
            <img v-if="showimg" @click="show()" src="../../../static/login/false.png" alt="">
            <img v-else @click="hide()" src="../../../static/login/true.png" alt="">
            我已阅读并同意《礼拜五用户协议》
          </div>

          <div class="butt">
            <button class="btn2" @click="reg" :class="dis?'bb':'btn2'" :disabled='dis'>会员注册</button>
          </div>
        </div>

      </div>

    </div>
    <Footer></Footer>

  </div>
</template>

<script>
  import Nav from '../com/Nav'
  import Footer from '../com/Footer'
  import Code from '../com/Code'
  import axios from 'axios'
  export default {
    name: "Reg",
    data(){
      return{
        title:'会员注册',
        iphoneTrue:false,
        bol:false,
        showimg:true,
        dis:true,
        dis1:true,
        dis2:false,
        iphone:'',
        password:'',
        repassword:'',
        iphoneyzm:'',
        code:'',
        yzm:true,
        iphonecode:'',
        tit:'获取验证码',
        num:60,
      }
    },
    components:{
      Nav,
      Code,
      Footer
    },
    methods:{
      yzIphone(){
        var reg=/^1[34578]\d{9}$/;
        if(!reg.test(this.iphone)){
          this.bol=true;
          this.iphoneTrue=false;
          // this.iphone='';
          return false;
        }else{
          this.bol=false;
          this.iphoneTrue=true;
        }
      },
      getCode(){
        this.yzm=false;
        this.dis2=true;
        this.dis1=false;
        this.iphonecode=1111;
        this.tit=this.num+'s';
        var timmer= setInterval(function(){
          this.num--;
          this.tit=this.num+'s';
          if(this.num==0){
            clearInterval(timmer);
            this.yzm=true;
            this.dis2=false;
            this.tit='获取验证码';
            this.num=3;
          }
        }.bind(this),1000)
      },
      show(){
        this.showimg=false;
        this.dis=false;
      },
      hide(){
        this.showimg=true;
        this.dis=true;
      },
      reg(){
        if(this.iphone.trim()==''){
          alert('手机号不能为空');
          return false;
        }
        if(this.password.trim()==''){
          alert('密码不能为空');
          return false;
        }
        if(this.repassword.trim()==''){
          alert('确认密码不能为空');
          return false;
        }
        if(this.code != this.$refs.zi.str2){
          alert('验证码不正确,请重新输入')
          this.$refs.zi.changeImg();
          this.code='';
          return false;
        }else if(this.iphoneyzm!=this.iphonecode){
          if(this.iphoneyzm.trim()==''){
            alert('验证码不能为空');
            return false;
          }else{
            alert('手机验证码不正确,请重新输入');
            return false;
          }
        }else{
          var params=new URLSearchParams();
          params.append('iphone',this.iphone);
          params.append('pwd',this.password);
          params.append('repwd',this.repassword);

          axios.post('/api/firday/reg.php',params).then(res=>{
            alert(res.data.msg);
            if(res.data.code==2 || res.data.code==1){
              this.$router.push('/login');
            }
          })
        }
      }
    },
    mounted(){

    }
  }

</script>

<style scoped>
  .head{
    width: 100%;
    height: 90px;
    padding-top: 40px;
  }
  .header-cont{
    width: 1280px;
    height: 50px;
    margin: 0 auto;
  }
  .header-cont img{
    width: 380px;
    height: 50px;
    margin-right: 100px;
    vertical-align: bottom;
  }
  .header-cont span{
    position: relative;
    font-size: 20px;
    color: #8c8c8c;
    height: 50px;
    line-height: 50px;
    position: relative;
  }
  .header-cont span:before{
    position: absolute;
    left: -50px;
    top: -6px;
    content: '';
    border: 1px solid #cecece;
    height: 38px;
    background: #cecece;
  }



  .con{
    width: 100%;
    height: 500px;
    background: url("../../../static/login/logreg.png") no-repeat center/cover ;
  }
  .reg-wrap{
    width: 1280px;
    height: 100%;
    margin: 0 auto;
  }

  .reg{
    width: 310px;
    height: 468px;
    padding: 30px 40px 0;
    background: #fff;
    float: right;
    border: 1px solid #cecece;
  }

  .iphoneCode{
    position: relative;
    width: 305px;
    height: 40px;
  }
  .iphoneCode img{
    position: absolute;
    top: 16px;
    right: 16px;
  }
  .inp{
    width: 281px;
    height: 16px;
    border: 1px solid #d3d3d3;
    padding:12px;
    font-size: 16px;
    background: #f9f9f9;
  }
  .repwd{
    margin-top: 30px;
  }

  .iphoneyzm{
    position: relative;
    margin-top: 30px;
    margin-bottom: 30px;
  }
  .yzmbtn{
    position: absolute;
    top: 5px;
    right: 10px;
    width: 100px;
    height: 30px;
    font-size: 14px;
    border-radius: 0;
    background: #498e3d;
  }
  .aa{
    position: absolute;
    top: 5px;
    right: 10px;
    width: 100px;
    height: 30px;
    font-size: 14px;
    border-radius: 0;
    background: #f2f2f2;
    color: #999;
  }

  .false{
    width: 305px;
    height: 30px;
    line-height: 30px;
  }
  .false span{
    color: #db2630;
  }
  .false span>img{
    width: 13px;
    height: 13px;
    margin-right: 5px;
    vertical-align: middle;
  }
  .yzm{
    display: flex;
    justify-content: space-between;
    width: 305px;
    height: 44px;
    padding-top: 30px;
  }

  .inp-yzm{
    width: 60px;
    height: 16px;
    padding:12px;
    border: 1px solid #d3d3d3;
    font-size: 16px;
    background: #f9f9f9;
    float: left;
  }
  .code{
    float: right;
    height: 40px;
  }

  .zi-dl{
    width: 305px;
    height: 10px;
    padding: 22px 0;
    font-size: 14px;
  }

  .zi-dl img{
    width: 18px;
    height: 18px;
    vertical-align: middle;
    cursor: pointer;
    margin-right: 10px;
  }
  button{
    width: 134px;
    height: 50px;
    color: #fff;
    font-size: 18px;
    border-radius: 5px;
  }

  .butt{
    width: 305px;
    height: 44px;
    margin-bottom: 15px;
    text-align: center;
  }

  .btn2{
    width: 305px;
    background: #498e3d;
  }
  .butt .bb{
    width: 305px;
    background: #f2f2f2;
    color: #999;
  }

</style>
